package flex.cc.basicinformation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import flex.cc.basicinformation.dao.ValueAddedServiceProviderConfigDao;
import flex.cc.basicinformation.entity.ValueAddedServiceProviderConfigEntity;
import flex.cc.basicinformation.service.ValueAddedServiceProviderConfigService;
import flex.cc.basicinformation.vo.ConfigVo;
import flex.cc.system.entity.DictCodeEntity;
import flex.cc.system.service.DictCodeService;
import flex.cc.system.vo.DictOptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wkangle
 * @className ValueAddedServiceProviderConfigServiceImpl
 * @description 增值服务服务商service
 * @time 2022-02-24 15:03:56
 */
@Service("valueAddedServiceProviderConfigService")
public class ValueAddedServiceProviderConfigServiceImpl extends ServiceImpl<ValueAddedServiceProviderConfigDao, ValueAddedServiceProviderConfigEntity> implements ValueAddedServiceProviderConfigService {

    @Resource
    private ValueAddedServiceProviderConfigDao valueAddedServiceProviderConfigDao;
    @Autowired
    private DictCodeService dictCodeService;

    /**
     * @param params 查询参数
     * @return
     * @description 根据参数查询增值服务服务商接口配置信息
     * @author wkangle
     * @time 2022-02-24 15:00:03
     * @exception/throws
     */
    @Override
    public ValueAddedServiceProviderConfigEntity getOneByParams(Map<String, Object> params) {
        return valueAddedServiceProviderConfigDao.getOneByParams(params);
    }

    /**
     * @return
     * @description 获取增值服务商配置相关信息
     * @author wkangle
     * @time 2022/03/01 0001 15:08
     * @exception/throws
     */
    @Override
    public List<ConfigVo> initConfigTypeList() {
        List<ConfigVo> initConfigTypeList = new ArrayList<>();
        Map<String, Object> params = new HashMap<>();
        params.put("typeCode", "cardUrlType");
        List<DictCodeEntity> cardUrlTypeList = dictCodeService.queryDictCodeListByParams(params);
        List<ConfigVo> children_cardUrlType = new ArrayList<>();
        for (DictCodeEntity entity : cardUrlTypeList) {
            ConfigVo configVo = new ConfigVo();
            configVo.setLabel(entity.getValue());
            configVo.setValue(entity.getCode());
            children_cardUrlType.add(configVo);
        }

        params.put("typeCode", "cardKeyType");
        List<DictCodeEntity> cardKeyTypeList = dictCodeService.queryDictCodeListByParams(params);
        List<ConfigVo> children_cardKeyType = new ArrayList<>();
        for (DictCodeEntity entity : cardKeyTypeList) {
            ConfigVo configVo = new ConfigVo();
            configVo.setLabel(entity.getValue());
            configVo.setValue(entity.getCode());
            children_cardKeyType.add(configVo);
        }

        params.put("typeCode", "cardThrCodeType");
        List<DictCodeEntity> cardThrCodeTypeList = dictCodeService.queryDictCodeListByParams(params);
        List<ConfigVo> children_cardThrCodeTypeList = new ArrayList<>();
        for (DictCodeEntity entity : cardThrCodeTypeList) {
            ConfigVo configVo = new ConfigVo();
            configVo.setLabel(entity.getValue());
            configVo.setValue(entity.getCode());
            children_cardThrCodeTypeList.add(configVo);
        }

        Map<String, Object> cardConfigTypeParams = new HashMap<String, Object>();
        cardConfigTypeParams.put("typeCode", "cardConfigType");
        List<DictCodeEntity> cardConfigTypeList = dictCodeService.queryDictCodeListByParams(cardConfigTypeParams);
        for (DictCodeEntity dictCodeEntity : cardConfigTypeList) {
            if ("0".equals(dictCodeEntity.getCode())) {
                ConfigVo cardUrlType = new ConfigVo();
                cardUrlType.setLabel(dictCodeEntity.getValue());
                cardUrlType.setValue(dictCodeEntity.getCode());
                cardUrlType.setChildren(children_cardUrlType);

                initConfigTypeList.add(cardUrlType);
            }
            if ("1".equals(dictCodeEntity.getCode())) {
                ConfigVo cardKeyType = new ConfigVo();
                cardKeyType.setLabel(dictCodeEntity.getValue());
                cardKeyType.setValue(dictCodeEntity.getCode());
                cardKeyType.setChildren(children_cardKeyType);

                initConfigTypeList.add(cardKeyType);
            }
            if ("2".equals(dictCodeEntity.getCode())) {
                ConfigVo cardKeyType = new ConfigVo();
                cardKeyType.setLabel(dictCodeEntity.getValue());
                cardKeyType.setValue(dictCodeEntity.getCode());
                cardKeyType.setChildren(children_cardThrCodeTypeList);

                initConfigTypeList.add(cardKeyType);
            }
        }
        return initConfigTypeList;
    }
}
